package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Activity;
import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.gameplay.Spell;

public class CastActivity extends Activity
{
    public int timeToCast = 0;
    private Spell spell;
    
    public CastActivity(Spell spell)
    {
        this.spell = spell;
    }
        
    public String getDescription()
    {
        int percentage = timeToCast * 100 / spell.castingTime;
        return Locale.spellLabel(spell.name, percentage, spell.getInstances());
    }

    public String getActionText()
    {
        if(isRunning())
        {
            return Locale.CASTING;
        }
        else
        {
            return Locale.CAST;
        }
    }
    
    public boolean isCompleted()
    {
        return !spell.isAvailable();
    }

    public void update(int delta, boolean action, boolean timeIsRunning)
    {
        if(timeIsRunning)
        {
            if(action)
            {
                timeToCast += Game.current.player.getCastDelta(delta);
                if(timeToCast >= spell.castingTime)
                {
                    // spell effect
                    spell.cast();
                    if(spell.isAvailable())
                    {
                        timeToCast = 0;
                        Game.current.resetActivity();
                    }
                }
            }
            else
            {
                timeToCast = 0;
            }
        }
    }

    public void paint(Graphics g, Rectangle activityArea)
    {
        GraphicStyles.paintDefaultActivity(g, this, activityArea, spell.icon);
    }
}
